<?
  ob_start("ob_gzhandler");

  require_once('db.php');
  require_once('util/misc.php');
  db_connect();

  $include_test = false;

  if (isset($_GET["id"])) {
?>
var centerPlace = <?=intval($_GET["id"])?>;
<?
  } else {
?>
var centerPlace;
<?
  }

  $query = 'SELECT id_TPT AS id, unix_timestamp(date_time_TPT) AS tm, longitude_TPT AS lng, latitude_TPT AS lat, test_tpt AS test';
  $query .= ', description_TPT as descr, user_TPT AS uid, username AS un, name AS fn';
  $query .= ', length_TPT as length, width_TPT as width, height_TPT as height, dispersed_TPT as isdisp, bag_eq_TPT as bageq';
  $query .= ', photo1_TPT as photo1, photo2_TPT as photo2, exclude_TPT as excluded, cleaned_tpt as cleaned, assigned_tpt as assigned';
  $query .= ' FROM v_tpt ORDER BY id_TPT';
  $result = mysql_query($query) or die("ERROR PERFORMING QUERY '".$query."': ".mysql_error());
?>

var places = [
<?
  $first = true;
  while ($row = mysql_fetch_assoc($result)) {
    // if (!$include_test && $row["test"] !== false && $row["test"] !== null && $row["test"] !== "")
    //   continue;

    if ($first)
      $first = false;
    else
      echo ",\n";
    echo "{id:".$row["id"].",lat:".$row["lat"].",lng:".$row["lng"].",tm:".$row["tm"].",uid:".$row["uid"];
    echo ",dl:".$row["length"].",dw:".$row["width"].",dh:".$row["height"];
    if ($row["isdisp"] === 'Y')
      echo ",disp:true";
    if (!is_null($row["bageq"]))
      echo ",bageq:".$row["bageq"];
    echo ",ph:[";
    $np = 0;
    if (!is_null($row["photo1"])) {
      echo "'".jsenc($row["photo1"])."'";
      $np++;
    }
    if (!is_null($row["photo2"])) {
      if ($np > 0)
        echo ",";
      echo "'".jsenc($row["photo2"])."'";
    }
    echo "]";

    if ($row["cleaned"] === 'C')
      $ic = 6;
    /* TJT added: && strlen($row["excluded"])!==0 */
    elseif (!is_null($row["excluded"]) && $row["excluded"] !== 'N' && strlen($row["excluded"]) !== 0)
      $ic = 1;
    elseif (!is_null($row["assigned"]) && $row["assigned"] !== 'N' && strlen($row["assigned"]) !== 0)
      $ic = 2;
    else
      $ic = 0;
    echo ",ic:".$ic;

    echo ",un:'".jsenc($row["un"])."',fn:'".$row["fn"]."',desc:'".jsenc($row["descr"])."'}";
  }

  mysql_free_result($result);

  $query = 'SELECT id_fls AS id, unix_timestamp(time_date_fls) AS tm, longitude_fls AS lng, latitude_fls AS lat';
  $query .= ', name_fls AS name, description_fls as descr';
  $query .= ' FROM ldi_flagstation_fls ORDER BY id_fls';
  $result = mysql_query($query) or die("ERROR PERFORMING QUERY '".$query."': ".mysql_error());

  while ($row = mysql_fetch_assoc($result)) {
    if ($first)
      $first = false;
    else
      echo ",\n";
    echo "{id:".$row["id"].",lat:".$row["lat"].",lng:".$row["lng"].",tm:".$row["tm"];
    echo ",name:'".jsenc($row["name"])."',desc:'".jsenc($row["descr"])."'";
    echo ",ic:4";
    echo "}";
  }

  mysql_free_result($result);
?>

];

<?

  $query = 'SELECT v.*,AsText(c.center_CNT) FROM v_tpt_county v LEFT JOIN ldi_county_cnt c on v.County=c.code_CNT';
  $result = mysql_query($query) or die("ERROR PERFORMING QUERY '".$query."': ".mysql_error());

?>

var county_totals = {
<?
  $first = true;
  while ($row = mysql_fetch_array($result)) {
    if ($first)
      $first = false;
    else
      echo ",\n";
    echo "'".$row[0]."':{";
    $splits = preg_split('/[()]/', $row[11]);
    $splits2 = preg_split('/ /', $splits[1]);
    echo "num:".$row[1].",vol:".$row[2].",lat:".$splits2[1].",lng:".$splits2[0];
    echo "}";
  }
?>

};

loadPlaces();
